<?php

	include("common.php");
	
	$result = mysql_query("SELECT * FROM `197_pages`");
	$pages = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($pages, $row);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除頁面</h1>
<div id="delete-page-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" defer="defer">
	$("#delete-page-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除頁面",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(page_id){
		$("#delete-page-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deletePage(page_id); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deletePage(page_id){
		$("#delete-page-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-page-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-page-dialog").dialog("open");
		$("#delete-page-dialog").load("pageDelete.php?page_id=" + page_id + "&ajax=true");
	}
</script>
<?php if(empty($pages)){ ?>
	<p>目前沒有頁面。</p>
<?php } else { ?>
	<ul>
		<?php foreach($pages as $row){ ?>
			<li><?php echo $row['title']; ?> - [ <a href="pageEdit.php?page_id=<?php echo $row['page_id']; ?>">編輯</a>｜<a href="pageDelete.php?page_id=<?php echo $row['page_id']; ?>" onclick="showConfirm(<?php echo $row['page_id']; ?>); return false;">刪除</a> ]</li>
		<?php } ?>
	</ul>
<?php } ?>
<p><a href="pageAdd.php">新增</a></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>